<template>
    <vol-box :lazy="true" v-model="model" title="选择Bom" :width="1200" :padding="0">
        <div>
            <bom ref="bomRef"></bom>
        </div>
        <template #footer>
            <div> <el-button type="primary" @click="onSelect">确认</el-button></div>
        </template>
    </vol-box>
</template>
<script setup>
import { ref, getCurrentInstance, nextTick } from 'vue'
const { proxy } = getCurrentInstance();

import bom from '@/views/mes/mes/MaterialsBom.vue';
//注意：1. '@/views/mes/mes/MES_Customer.vue'改为想要选择的vue文件
//2.在MES_Customer.vue的onInit中应该重新设置表格高度,代码实现如下：
// const onInited = async () => {
//     //判断当前页面路由地址是不是选择的数据地址
//     if (proxy.$route.path=='/MES_ProductionOrder') {
//          //设置表格高度
//          gridRef.height=350;
//          //设置为单选
//          gridRef.single=true;
//     }
// }

const bomRef = ref();
const model = ref(false)
//回调
const emit = defineEmits('onSelectBom')
const open = (materialId) => {
    //打开主表选择数据
    model.value = true;
    //打开时刷新界面数据
    nextTick(() => {
        bomRef.value.$refs.grid.searchFormFields.MaterialId = materialId
        bomRef.value?.$refs.grid?.search()
    });
}
//选择数据
const onSelect = () => {
    //主表的选择数据回写到主表的表单上
    let rows = bomRef.value.$refs.grid.getSelectRows();
    if (!rows.length) {
        return proxy.$message.error('请选择数据');
    }
    model.value = false;
    emit('onSelectBom', rows)
}
//暴露选择弹出框方法
defineExpose({ open })
</script>
<style lang="less" scoped>
.search-form {
    display: flex;
    padding: 10px;
    line-height: 34px;

    button {
        margin-left: 10px;
    }
}
</style>